//
//  ViewController.m
//  NetworkMudleDemo
//
//  Created by 马晨曦 on 2019/5/13.
//  Copyright © 2019 VergilMa. All rights reserved.
//

#import "ViewController.h"
#import "DataManager.h"
#import "DataConverter.h"
#import "ConverterProtocol.h"
@interface ViewController ()<DataManagerProtocol>
@property (weak, nonatomic) IBOutlet UILabel *aLable;

@property (nonatomic, strong) id<ConverterProtocol> converterA;

@property (nonatomic, strong) DataManager *dataManager;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.converterA = [[DataConverter alloc]init];
    
}
- (IBAction)click0:(id)sender {
    [self.dataManager refreshDataWithType:dataTypeDef];
}
- (IBAction)click1:(id)sender {
    [self.dataManager refreshDataWithType:dataTypeA];
}
- (IBAction)click2:(id)sender {
    [self.dataManager refreshDataWithType:dataTypeB];
}

#pragma mark - delegate
- (void)dataManagerDidSuccess:(DataManager *)manager{
    NSDictionary *dic = [manager fetchDataWithConverter:self.converterA];
    self.aLable.text = [NSString stringWithFormat:@"%@",dic[@"key"]];
}

#pragma mark - getter
- (DataManager *)dataManager{
    if (!_dataManager) {
        _dataManager = [[DataManager alloc]init];
        _dataManager.delegate = self;
        
    }return _dataManager;
}


@end
